<?php

namespace App\Models;

/**
 * App\Models\AdminRoleModel
 *
 * @property int $id
 * @property int $state
 * @property string $title
 * @property string $permission_md5
 * @property array $permission_list
 * @property int $created_at
 * @property int $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel wherePermissionList($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel wherePermissionMd5($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel whereState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AdminRoleModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class AdminRoleModel extends BaseModel
{
    protected $table = 'admin_role';

    protected $dateFormat = 'U';

    protected $casts = [
        'updated_at' => 'datetime',
        'created_at' => 'datetime',
        'permission_list' => 'json',
        'state' => 'bool',
    ];

    public function setPermissionMd5Attribute($value)
    {
        sort($value);
        $this->attributes['permission_md5'] = md5(json_encode($value));
    }
}
